package com.arouter.demo.searchmodule.inject;

import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.arouter.demo.baselib.router.RouterPath;
import com.arouter.demo.searchmodule.R;
import com.arouter.demo.searchmodule.entity.ObjEntity;
import com.arouter.demo.searchmodule.entity.ObjParcelable;

import java.util.List;
import java.util.Map;

/**
 *
 */
@Route(path = RouterPath.AUTO_INJECT)
public class AutoInjectActivity extends AppCompatActivity {

    @Autowired
    ObjEntity objEntity;

    @Autowired
    ObjParcelable objParcelable;

    @Autowired
    List<ObjEntity> objList;

    @Autowired
    Map<String, List<ObjEntity>> map;


    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_auto_inject);

        ARouter.getInstance().inject(this);

        TextView tvClassName = findViewById(R.id.class_name);
        tvClassName.setText(AutoInjectActivity.class.getName());

        TextView tvEntity = findViewById(R.id.tv_receive_object_value);
        if (objEntity != null) {
            tvEntity.setText(objEntity.toString());
        }

        TextView tvSerialEntity = findViewById(R.id.tv_receive_serial_obj_value);
        if (objParcelable != null) {
            tvSerialEntity.setText(objParcelable.toString());
        }


        TextView tvMap = findViewById(R.id.tv_receive_map_value);
        if (map != null) {
            List<ObjEntity> objList = map.get("testMap");
            if (objList != null) {
                StringBuilder text = new StringBuilder("解析Map中的数据：\n");

                for (ObjEntity objEntity : objList) {
                   text.append(objEntity.toString()).append("\n");
                }

                tvMap.setText(text.toString());
            }
        }


        TextView tvList = findViewById(R.id.tv_receive_list_value);
        if (objList != null) {
            StringBuilder text = new StringBuilder("解析List中的数据：\n");
            for (ObjEntity objEntity : objList) {
                text.append(objEntity.toString()).append("\n");
            }
            tvList.setText(text);
        }

    }
}
